<template>
  <div class="app-container">
<!--    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">-->
<!--      <el-form-item label="盒子名称" prop="gameBoxName">-->
<!--        <el-input-->
<!--          v-model="queryParams.gameBoxName"-->
<!--          placeholder="请输入盒子名称"-->
<!--          clearable-->
<!--          -->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="单发票价" prop="gameBoxPrice">-->
<!--        <el-input-->
<!--          v-model="queryParams.gameBoxPrice"-->
<!--          placeholder="请输入单发票价"-->
<!--          clearable-->
<!--          -->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="赏品种类" prop="gameBoxNumber">-->
<!--        <el-input-->
<!--          v-model="queryParams.gameBoxNumber"-->
<!--          placeholder="请输入赏品种类"-->
<!--          clearable-->
<!--          -->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="对碰倍率" prop="pair">-->
<!--        <el-input-->
<!--          v-model="queryParams.pair"-->
<!--          placeholder="请输入对碰倍率"-->
<!--          clearable-->
<!--          -->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="三连倍率" prop="triple">-->
<!--        <el-input-->
<!--          v-model="queryParams.triple"-->
<!--          placeholder="请输入三连倍率"-->
<!--          clearable-->
<!--          -->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="全家福倍率" prop="full">-->
<!--        <el-input-->
<!--          v-model="queryParams.full"-->
<!--          placeholder="请输入全家福倍率"-->
<!--          clearable-->
<!--          -->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="清台倍率" prop="emptys">-->
<!--        <el-input-->
<!--          v-model="queryParams.emptys"-->
<!--          placeholder="请输入清台倍率"-->
<!--          clearable-->
<!--          -->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="幸运数倍率" prop="lucky">-->
<!--        <el-input-->
<!--          v-model="queryParams.lucky"-->
<!--          placeholder="请输入幸运数倍率"-->
<!--          clearable-->
<!--          -->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item>-->
<!--        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
<!--        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
<!--      </el-form-item>-->
<!--    </el-form>-->

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:gameBox:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:gameBox:edit']"
        >修改</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['system:gameBox:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['system:gameBox:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="gameBoxList" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="盒子ID" align="center" prop="gameBoxId" />
      <el-table-column label="盒子名称" align="center" prop="gameBoxName" />
      <el-table-column label="单发票价" align="center" prop="gameBoxPrice" >
       <template slot-scope="scope">
         <el-tag v-if="scope.row.gameBoxPrice!== null">{{scope.row.gameBoxPrice}}元</el-tag>
       </template>
      </el-table-column>

      <el-table-column label="赏品种类(多少种颜色物品参与对碰)" align="center" prop="gameBoxNumber" width="150">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.gameBoxNumber!== null">{{scope.row.gameBoxNumber}}种不同赏品</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="盒子状态" align="center" prop="gameBoxStatus" >
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.gameBoxStatus === 1">启用</el-tag>
          <el-tag  type="danger" v-else>停用</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="对碰倍率" align="center" prop="pair" width="200">
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.pair!== null">{{scope.row.pair}}倍</el-tag>||<el-tag type="success">可获{{scope.row.pair}}次摆放机会</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="三连倍率" align="center" prop="triple"  width="200">
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.triple!== null">{{scope.row.triple}}倍</el-tag>||<el-tag type="success">可获{{scope.row.triple}}次摆放机会</el-tag>
          </template>
      </el-table-column>
      <el-table-column label="全家福倍率" align="center" prop="full"  width="200">
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.full!== null">{{scope.row.full}}倍</el-tag>||<el-tag type="success">可获{{scope.row.full}}次摆放机会</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="清台倍率" align="center" prop="emptys" width="200">
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.emptys!== null">{{scope.row.emptys}}倍</el-tag>||<el-tag type="success">可获{{scope.row.emptys}}次摆放机会</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="幸运数倍率" align="center" prop="lucky" width="200">
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.lucky!== null">{{scope.row.lucky}}倍</el-tag>||<el-tag type="success">可获{{scope.row.lucky}}次摆放机会</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="盒子封面图" align="center" prop="imgUrl" width="240">
        <template slot-scope="scope">
          <image-preview :src="scope.row.imgUrl" width="240px" height="100px"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="150">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-platform-eleme"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:gameBox:edit']"
          >新增盒子内赏品</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:gameBox:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:gameBox:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改gameBox对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="盒子名称" prop="gameBoxName">
          <el-input v-model="form.gameBoxName" placeholder="请输入盒子名称" />
        </el-form-item>
        <el-form-item label="单发票价" prop="gameBoxPrice">
          <el-input-number  :precision="2" step="1"  v-model="form.gameBoxPrice" placeholder="请输入单发票价" /> /单发
        </el-form-item>
        <el-form-item label="赏品种类" prop="gameBoxNumber">
          <el-input-number  :precision="0" step="1" :min="10" :max="100" v-model="form.gameBoxNumber" placeholder="请输入赏品种类" />
        </el-form-item>
        <el-form-item label="对碰倍率" prop="pair">
          <el-input-number  :precision="0" step="1" v-model="form.pair" placeholder="请输入对碰倍率" />
        </el-form-item>
        <el-form-item label="三连倍率" prop="triple">
          <el-input-number  :precision="0" step="1" v-model="form.triple" placeholder="请输入三连倍率" />
        </el-form-item>
        <el-form-item label="全家福倍率" prop="full">
          <el-input-number  :precision="0" step="1" v-model="form.full" placeholder="请输入全家福倍率" />
        </el-form-item>
        <el-form-item label="清台倍率" prop="emptys">
          <el-input-number  :precision="0" step="1" v-model="form.emptys" placeholder="请输入清台倍率" />
        </el-form-item>
        <el-form-item label="幸运数倍率" prop="lucky">
            <el-input-number  :precision="0" step="1" v-model="form.lucky" placeholder="请输入幸运数倍率" />
        </el-form-item>
        <el-form-item label="盒子封面图">
          <image-upload v-model="form.imgUrl" :multiple="false"  />
        </el-form-item>

        <el-form-item label="盒子状态" prop="gameBoxStatus">
          <el-select v-model="form.gameBoxStatus">
            <el-option label="启用" :value="1"></el-option>
            <el-option label="停用" :value="0"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listGameBox, getGameBox, delGameBox, addGameBox, updateGameBox } from "@/api/system/gameBox";

export default {
  name: "GameBox",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // gameBox表格数据
      gameBoxList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        gameBoxName: null,
        gameBoxPrice: null,
        gameBoxNumber: null,
        gameBoxStatus: null,
        pair: null,
        triple: null,
        full: null,
        emptys: null,
        lucky: null,
        imgUrl: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        gameBoxName: [
          { required: true, message: "盒子名称不能为空", trigger: "blur" }
        ],
        gameBoxPrice: [
          { required: true, message: "单发票价不能为空", trigger: "blur" }
        ],
        gameBoxNumber: [
          { required: true, message: "赏品种类不能为空", trigger: "blur" }
        ],
        gameBoxStatus: [
          { required: true, message: "盒子状态不能为空", trigger: "blur" }
        ],
        pair: [
          { required: true, message: "对碰倍率不能为空", trigger: "blur" }
        ],
        full: [
          { required: true, message: "全家福倍率不能为空", trigger: "blur" }
        ],
        emptys: [
          { required: true, message: "清台倍率不能为空", trigger: "blur" }
        ],
        lucky: [
          { required: true, message: "幸运数倍率不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询gameBox列表 */
    getList() {
      this.loading = true;
      listGameBox(this.queryParams).then(response => {
        this.gameBoxList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        gameBoxId: null,
        gameBoxName: null,
        gameBoxPrice: null,
        gameBoxNumber: null,
        gameBoxStatus: 0,
        createTime: null,
        updateTime: null,
        pair: null,
        triple: null,
        full: null,
        emptys: null,
        lucky: null,
        imgUrl: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.gameBoxId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加乌龟对对碰盒子";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const gameBoxId = row.gameBoxId || this.ids
      getGameBox(gameBoxId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改乌龟对对碰盒子";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.gameBoxId != null) {
            updateGameBox(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addGameBox(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const gameBoxIds = row.gameBoxId || this.ids;
      this.$modal.confirm('是否确认删除gameBox编号为"' + gameBoxIds + '"的数据项？').then(function() {
        return delGameBox(gameBoxIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/gameBox/export', {
        ...this.queryParams
      }, `gameBox_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
